package com.ctshk.app.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.OperationLogDTO;
import com.ctshk.rpc.system.dto.ScenicDTO;
import com.ctshk.rpc.system.req.*;
import com.ctshk.rpc.system.service.ISceneService;
import com.ctshk.rpc.system.service.IScenicGetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author xuhui
 * @since 1/27/2021
 */

@Api(value = "景点资料", tags = "景点资料主数据")
@RestController
@RequestMapping("/main/data/scenic")
public class ScenicController extends BaseController {

    @DubboReference
    ISceneService ISceneService;

    @DubboReference
    IScenicGetService scenicGetService;

    @ApiOperation(value = "同步景点资料", notes = "同步景点资料")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "爬取景点信息", operDesc = "爬取景点信息")
    @GetMapping("/sync")
    public void sync(@RequestParam(value = "flage") boolean flage,
                     @RequestParam(value = "name") String name,
                     @RequestParam(value = "count") int count) {
        scenicGetService.scenicTask(flage, StringUtils.isEmpty(name) ? null : name, count);
    }

    @ApiOperation(value = "景点资料列表", notes = "查询景点资料列表(无需参数)")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "景点资料主数据", operDesc = "景点资料列表主数据")
    @GetMapping("/list")
    public Result<PageResponse<ScenicDTO>> list() {
        ScenicListReq scenicListReq = new ScenicListReq();
        scenicListReq.setStatus(0);
        PageResponse<ScenicDTO> list = ISceneService.list(scenicListReq, getCurrentUser(getRequest()));
        return Result.success(list);
    }

    @ApiOperation(value = "景点资料列表", notes = "查询景点资料列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "景点资料主数据", operDesc = "景点资料列表主数据")
    @PostMapping("/list")
    public Result<PageResponse<ScenicDTO>> list(@RequestBody ScenicListReq scenicListReq) {
        PageResponse<ScenicDTO> list = ISceneService.list(scenicListReq, getCurrentUser(getRequest()));
        return Result.success(list);
    }

    @ApiOperation(value = "新增景点资料", notes = "新增景点资料")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "景点资料主数据", operDesc = "新增景点资料主数据")
    @PostMapping("/add")
    public Result<Integer> add(@RequestBody ScenicAddReq scenicAddReq) {
        return ISceneService.add(scenicAddReq, getCurrentUser(getRequest()));

    }

    @ApiOperation(value = "编辑景点资料", notes = "编辑景点资料")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "景点资料主数据", operDesc = "编辑景点资料主数据")
    @PostMapping("/update")
    public Result<Integer> update(@RequestBody ScenicUpdateReq scenicUpdateReq) {
        return ISceneService.update(scenicUpdateReq, getCurrentUser(getRequest()));

    }

    @ApiOperation(value = "修改景点资料状态", notes = "修改景点资料状态")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "景点资料主数据", operDesc = "修改景点资料状态主数据")
    @PostMapping("/update/status")
    public Result<Integer> modifyStatus(@RequestBody ScenicUpdateStatusReq scenicUpdateStatusReq) {
        return ISceneService.modifyStatus(scenicUpdateStatusReq, getCurrentUser(getRequest()));

    }

    @ApiOperation(value = "删除景点资料", notes = "删除景点资料")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.DELETE, operTitle = "景点资料主数据", operDesc = "删除景点资料主数据")
    @PostMapping("/delete")
    public Result<Integer> delete(@RequestBody ScenicDeleteReq scenicDeleteReq) {
        return ISceneService.delete(scenicDeleteReq.getId(), getCurrentUser(getRequest()));

    }

    @ApiOperation(value = "景点资料详情", notes = "景点资料详情")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "景点资料主数据", operDesc = "景点资料详情主数据")
    @PostMapping("/detail")
    public Result<ScenicDTO> detail(@RequestBody ScenicDetailReq scenicDetailReq) {
        return ISceneService.detail(scenicDetailReq);

    }

    @ApiOperation(value = "操作记录--该接口已被弃用请使用新的接口", notes = "操作记录--该接口已被弃用请使用新的接口")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "操作记录----该接口已被弃用", operDesc = "操作记录主数据----该接口已被弃用")
    @GetMapping("/operation/records")
    public Result<List<OperationLogDTO>> operationRecords(@RequestBody ScenicAddReq scenicAddReq) {
        List<OperationLogDTO> list = ISceneService.opeartionRecords(getCurrentUser(getRequest()));
        return Result.success(list);
    }

    @ApiOperation(value = "拉取长隆景点资源信息", notes = "拉取长隆景点资源信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "拉取长隆景点资源信息", operDesc = "拉取长隆景点资源信息")
    @PostMapping("/save")
    public Result saveScenic() {
        return ISceneService.saveScenic(getCurrentUser(getRequest()));
    }
}